package com.mg.controller;

import com.mg.service.BaseService;
import com.mg.utils.JsonUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author: Damen
 * @Dcsription: 公共接口控制
 * @Data: Created in 23:00 2017/8/8
 * @Modified By:
 */
@Controller
@RequestMapping("/base")
public class BaseController {
    @Autowired
    BaseService baseService;

    @RequestMapping("/baseAction")
    @ResponseBody
    public String ajaxAction(
            @RequestParam(value = "paramMap", required = false) String paramStr,
            @RequestParam(value = "sqlKey", required = false) String sqlKey) {
        List<Map<String, Object>> objlist = baseService.selectList(sqlKey, paramStr);
        String json;
        try {
            json = JsonUtils.toJson(objlist);
        } catch (Exception e) {
            json = "[]";
        }
        return json;
    }
}
